package com.operator.Activitys.http.manager;

import android.app.Activity;
import android.util.Log;

import com.operator.Activitys.bean.Back;
import com.operator.Activitys.bean.CardOrder;
import com.operator.Activitys.bean.InstallOrder;
import com.operator.Activitys.bean.MoneyState;
import com.operator.Activitys.bean.MsgNotice;
import com.operator.Activitys.bean.OrderPayState;
import com.operator.Activitys.bean.PrizePunish;
import com.operator.Activitys.bean.PurchaseOrder;
import com.operator.Activitys.bean.PutForwardList;
import com.operator.Activitys.bean.RechargeList;
import com.operator.Activitys.bean.SearchShop;
import com.operator.Activitys.bean.ShopConfirmMsg;
import com.operator.Activitys.bean.State;
import com.operator.Activitys.bean.TradeList;
import com.operator.Activitys.bean.TransferList;
import com.operator.Activitys.bean.pack.SalesRecordJsonPack;
import com.operator.Activitys.bean.pack.StockQueryJsonPack;
import com.operator.Activitys.bean.pack.UserJsonPack;
import com.operator.Activitys.http.ApiService;
import com.operator.Activitys.http.NetWorkMgr;
import com.operator.Activitys.http.api.UserAPI;
import com.operator.Activitys.utils.Constant;

import org.simple.eventbus.EventBus;

import java.util.List;

import rx.Observer;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * 项目名称：
 * 类描述：所有 用户 接口管理 manager
 * 创建人：张飞祥
 * 创建时间：2018/5/9 0027 下午 1:33
 * 修改人：张飞祥
 * 修改时间：2018/5/9 0027 下午 1:33
 * 修改备注：
 */
public class UserManager {

    private static UserAPI mUserAPI;
    private static ApiService mApiService;
    private static Activity mActivity;
    private static int mTaskId;

    //加载数据类型
    private int RefType = Constant.FIRST_LOAD;

    private static class UserApiManagerHolder {
        private static final UserManager INSTANCE = new UserManager();
    }
    public static final UserManager getUserApiManager(Activity activity, int taskId) {
        mUserAPI = NetWorkMgr.getInstance(activity)
                .getServiceAPI(UserAPI.class);
        mApiService = ApiService.getApiService();
        mActivity = activity;
        mTaskId = taskId;
        return UserApiManagerHolder.INSTANCE;
    }

    public void getType(int type){
        RefType=type;
    }

    /**
     * 用户注册
     */
    public void userRegister(String sessionId,String storeName,String mobile,String area, String address,
                             String linkTel,String countermanName,String CountermanTel, String vCod,String pwd) {
        Subscription subscription = mUserAPI
                .userRegister(sessionId,storeName, mobile, area, address,linkTel, countermanName, CountermanTel,vCod, pwd).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<State>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        //加载出错,可用于 “页面” 提示信息
                        EventBus.getDefault().post("onCompleted", Constant.BUS_REGISTER_ERROR);
                        //log 打印
                        Log.e(mActivity.getClass().getSimpleName(),"structureList 错误" + e.toString());
                    }
                    @Override
                    public void onNext(State bean) {
                        //返回成功 数据处理
                        EventBus.getDefault().post(bean, Constant.BUS_REGISTER);
                    }
                });
        mApiService.getCompositeSubscription(mTaskId).add(subscription);
    }

    /**
     * 用户登录
     */
    public void userLogin(String mobile,String pwd) {
        Subscription subscription = mUserAPI
                .userLogin(mobile,pwd).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<UserJsonPack>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        //加载出错,可用于 “页面” 提示信息
                        EventBus.getDefault().post("onCompleted", Constant.BUS_LOGIN_ERROR);
                        //log 打印
                        Log.e(mActivity.getClass().getSimpleName(),"structureList 错误" + e.toString());
                    }
                    @Override
                    public void onNext(UserJsonPack pack) {
                        //返回成功 数据处理
                        EventBus.getDefault().post(pack, Constant.BUS_LOGIN);
                    }
                });
        mApiService.getCompositeSubscription(mTaskId).add(subscription);
    }

    /**
     * 店铺认证 获取银行种类
     */
    public void userBackList() {
        Subscription subscription = mUserAPI
                .userBackList().subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<List<Back>>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        //加载出错,可用于 “页面” 提示信息
                        EventBus.getDefault().post("onCompleted", Constant.BUS_SHOP_BACK_LIST_ERROR);
                        //log 打印
                        Log.e(mActivity.getClass().getSimpleName(),"structureList 错误" + e.toString());
                    }
                    @Override
                    public void onNext(List<Back> list) {
                        //返回成功 数据处理
                        EventBus.getDefault().post(list, Constant.BUS_SHOP_BACK_LIST);
                    }
                });
        mApiService.getCompositeSubscription(mTaskId).add(subscription);
    }

    /**
     * 店铺认证 获取认证信息
     */
    public void userConfirmMsg(int storeId) {
        Subscription subscription = mUserAPI
                .userConfirmMsg(storeId).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<ShopConfirmMsg>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        //加载出错,可用于 “页面” 提示信息
                        EventBus.getDefault().post("onCompleted", Constant.BUS_SHOP_CONFIRM_MSG_ERROR);
                        //log 打印
                        Log.e(mActivity.getClass().getSimpleName(),"structureList 错误" + e.toString());
                    }
                    @Override
                    public void onNext(ShopConfirmMsg bean) {
                        //返回成功 数据处理
                        EventBus.getDefault().post(bean, Constant.BUS_SHOP_CONFIRM_MSG);
                    }
                });
        mApiService.getCompositeSubscription(mTaskId).add(subscription);
    }

    /**
     * 店铺认证 修改认证信息
     */
    public void userUpdateConfirmMsg(int storeId, int authenticationInfoId,
                                     String bankCardNum,String bankCategory) {
        Subscription subscription = mUserAPI
                .userUpdateConfirmMsg(storeId,authenticationInfoId,bankCardNum,bankCategory).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<State>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        //加载出错,可用于 “页面” 提示信息
                        EventBus.getDefault().post("onCompleted", Constant.BUS_SHOP_UPDATE_CONFIRM_MSG_ERROR);
                        //log 打印
                        Log.e(mActivity.getClass().getSimpleName(),"structureList 错误" + e.toString());
                    }
                    @Override
                    public void onNext(State bean) {
                        //返回成功 数据处理
                        EventBus.getDefault().post(bean, Constant.BUS_SHOP_UPDATE_CONFIRM_MSG);
                    }
                });
        mApiService.getCompositeSubscription(mTaskId).add(subscription);
    }

    /**
     * 店铺认证 获取银行种类
     */
    public void userShopSubmit(int storeId,String bankCardNum, String idCardNum,String bankCardHolder,
                               String bankCategory,String idCardImgUrl, String businessLicenceImgUrl, String mtImgUrl,
                               String dnImgUrl) {
        Subscription subscription = mUserAPI
                .userShopSubmit(storeId,bankCardNum,idCardNum,bankCardHolder,bankCategory
                        ,idCardImgUrl, businessLicenceImgUrl, mtImgUrl,dnImgUrl).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<State>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        //加载出错,可用于 “页面” 提示信息
                        EventBus.getDefault().post("onCompleted", Constant.BUS_SHOP_SUBMIT_ERROR);
                        //log 打印
                        Log.e(mActivity.getClass().getSimpleName(),"structureList 错误" + e.toString());
                    }
                    @Override
                    public void onNext(State bean) {
                        //返回成功 数据处理
                        EventBus.getDefault().post(bean, Constant.BUS_SHOP_SUBMIT);
                    }
                });
        mApiService.getCompositeSubscription(mTaskId).add(subscription);
    }

    /**
     * 我的订单 -------> 号卡订单 记录
     */
    public void userCardOrder(int storeId,int pageIndex,int pageSize) {
        Subscription subscription = mUserAPI
                .userCardOrder(storeId,pageIndex,pageSize).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<List<CardOrder>>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        //返回成功 数据处理
                        EventBus.getDefault().post(e.toString(), Constant.BUS_MY_CARD_ORDER_LIST_ERROR);
                        //log 打印
                        Log.e(mActivity.getClass().getSimpleName(),"structureList 错误" + e.toString());
                    }
                    @Override
                    public void onNext(List<CardOrder> list) {

                        if(RefType== Constant.FIRST_LOAD){
                            //返回成功 首次加载数据处理
                            EventBus.getDefault().post(list, Constant.BUS_MY_CARD_ORDER_LIST);
                        }else{
                            //返回成功 上拉加载数据处理
                            EventBus.getDefault().post(list, Constant.BUS_MY_CARD_ORDER_LIST_FOOT);
                        }
                    }
                });
        mApiService.getCompositeSubscription(mTaskId).add(subscription);
    }

    /**
     * 我的订单 -------> 号卡订单 支付
     */
    public void userCardPay(int storeId,int orderId) {
        Subscription subscription = mUserAPI
                .userCardPay(storeId,orderId).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<OrderPayState>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        //加载出错,可用于 “页面” 提示信息
                        EventBus.getDefault().post("onCompleted", Constant.BUS_MY_CARD_ORDER_PAY_ERROR);
                        //log 打印
                        Log.e(mActivity.getClass().getSimpleName(),"structureList 错误" + e.toString());
                    }
                    @Override
                    public void onNext(OrderPayState bean) {
                        //返回成功 数据处理
                        EventBus.getDefault().post(bean, Constant.BUS_MY_CARD_ORDER_PAY);
                    }
                });
        mApiService.getCompositeSubscription(mTaskId).add(subscription);
    }


    /**
     * 我的订单 -------> 宽带订单 记录
     */
    public void userInstallOrder(int storeId,int pageIndex,int pageSize) {
        Subscription subscription = mUserAPI
                .userInstallOrder(storeId,pageIndex,pageSize).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<List<InstallOrder>>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        //返回成功 数据处理
                        EventBus.getDefault().post(e.toString(), Constant.BUS_MY_INSTALL_ORDER_LIST_ERROR);
                        //log 打印
                        Log.e(mActivity.getClass().getSimpleName(),"structureList 错误" + e.toString());
                    }
                    @Override
                    public void onNext(List<InstallOrder> list) {

                        if(RefType== Constant.FIRST_LOAD){
                            //返回成功 首次加载数据处理
                            EventBus.getDefault().post(list, Constant.BUS_MY_INSTALL_ORDER_LIST);
                        }else{
                            //返回成功 上拉加载数据处理
                            EventBus.getDefault().post(list, Constant.BUS_MY_INSTALL_ORDER_LIST_FOOT);
                        }
                    }
                });
        mApiService.getCompositeSubscription(mTaskId).add(subscription);
    }


    /**
     * 我的订单 -------> 宽带订单 支付
     */
    public void userInstallPay(int storeId,int broadbandOrderId) {
        Subscription subscription = mUserAPI
                .userInstallPay(storeId,broadbandOrderId).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<OrderPayState>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        //加载出错,可用于 “页面” 提示信息
                        EventBus.getDefault().post("onCompleted", Constant.BUS_MY_INSTALL_ORDER_PAY_ERROR);
                        //log 打印
                        Log.e(mActivity.getClass().getSimpleName(),"structureList 错误" + e.toString());
                    }
                    @Override
                    public void onNext(OrderPayState bean) {
                        //返回成功 数据处理
                        EventBus.getDefault().post(bean, Constant.BUS_MY_INSTALL_ORDER_PAY);
                    }
                });
        mApiService.getCompositeSubscription(mTaskId).add(subscription);
    }

    /**
     * 店铺 充值
     */
    public void userRecharge(int storeId,int money,String type) {
        Subscription subscription = mUserAPI
                .userRecharge(storeId,money,type).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<MoneyState>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        //加载出错,可用于 “页面” 提示信息
                        EventBus.getDefault().post("onCompleted", Constant.BUS_MY_RECHARGE_ERROR);
                        //log 打印
                        Log.e(mActivity.getClass().getSimpleName(),"structureList 错误" + e.toString());
                    }
                    @Override
                    public void onNext(MoneyState bean) {
                        //返回成功 数据处理
                        EventBus.getDefault().post(bean, Constant.BUS_MY_RECHARGE);
                    }
                });
        mApiService.getCompositeSubscription(mTaskId).add(subscription);
    }

    /**
     * 充值记录
     */
    public void userRechargeList(int storeId,int pageIndex,int pageSize) {
        Subscription subscription = mUserAPI
                .userRechargeList(storeId,pageIndex,pageSize).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<List<RechargeList>>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        //返回成功 数据处理
                        EventBus.getDefault().post(e.toString(), Constant.BUS_MY_RECHARGE_LIST_ERROR);
                        //log 打印
                        Log.e(mActivity.getClass().getSimpleName(),"structureList 错误" + e.toString());
                    }
                    @Override
                    public void onNext(List<RechargeList> list) {

                        if(RefType== Constant.FIRST_LOAD){
                            //返回成功 首次加载数据处理
                            EventBus.getDefault().post(list, Constant.BUS_MY_RECHARGE_LIST);
                        }else{
                            //返回成功 上拉加载数据处理
                            EventBus.getDefault().post(list, Constant.BUS_MY_RECHARGE_LIST_FOOT);
                        }
                    }
                });
        mApiService.getCompositeSubscription(mTaskId).add(subscription);
    }


    /**
     * 店铺 提现
     */
    public void userPutForward(int storeId,double money) {
        Subscription subscription = mUserAPI
                .userPutForward(storeId,money).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<MoneyState>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        //加载出错,可用于 “页面” 提示信息
                        EventBus.getDefault().post("onCompleted", Constant.BUS_MY_PUT_FORWARD_ERROR);
                        //log 打印
                        Log.e(mActivity.getClass().getSimpleName(),"structureList 错误" + e.toString());
                    }
                    @Override
                    public void onNext(MoneyState bean) {
                        //返回成功 数据处理
                        EventBus.getDefault().post(bean, Constant.BUS_MY_PUT_FORWARD);
                    }
                });
        mApiService.getCompositeSubscription(mTaskId).add(subscription);
    }

    /**
     * 提现记录
     */
    public void userPutForwardList(int storeId,int pageIndex,int pageSize) {
        Subscription subscription = mUserAPI
                .userPutForwardList(storeId,pageIndex,pageSize).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<List<PutForwardList>>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        //返回成功 数据处理
                        EventBus.getDefault().post(e.toString(), Constant.BUS_MY_PUT_FORWARD_LIST_ERROR);
                        //log 打印
                        Log.e(mActivity.getClass().getSimpleName(),"structureList 错误" + e.toString());
                    }
                    @Override
                    public void onNext(List<PutForwardList> list) {

                        if(RefType== Constant.FIRST_LOAD){
                            //返回成功 首次加载数据处理
                            EventBus.getDefault().post(list, Constant.BUS_MY_PUT_FORWARD_LIST);
                        }else{
                            //返回成功 上拉加载数据处理
                            EventBus.getDefault().post(list, Constant.BUS_MY_PUT_FORWARD_LIST_FOOT);
                        }
                    }
                });
        mApiService.getCompositeSubscription(mTaskId).add(subscription);
    }

    /**
     * 店铺 搜索
     */
    public void userSearchShop(String MHStorename,String ThisStoreName) {
        Subscription subscription = mUserAPI
                .userSearchShop(MHStorename,ThisStoreName).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<List<SearchShop>>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        //加载出错,可用于 “页面” 提示信息
                        EventBus.getDefault().post("onCompleted", Constant.BUS_MY_SEARCH_SHOP_ERROR);
                        //log 打印
                        Log.e(mActivity.getClass().getSimpleName(),"structureList 错误" + e.toString());
                    }
                    @Override
                    public void onNext(List<SearchShop> list) {
                        //返回成功 数据处理
                        EventBus.getDefault().post(list, Constant.BUS_MY_SEARCH_SHOP);
                    }
                });
        mApiService.getCompositeSubscription(mTaskId).add(subscription);
    }

    /**
     * 店铺 转账
     */
    public void userTransfer(String fromStoreName,String toStoreName, double money) {
        Subscription subscription = mUserAPI
                .userTransfer(fromStoreName,toStoreName,money).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<MoneyState>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        //加载出错,可用于 “页面” 提示信息
                        EventBus.getDefault().post("onCompleted", Constant.BUS_MY_TRANSFER_ERROR);
                        //log 打印
                        Log.e(mActivity.getClass().getSimpleName(),"structureList 错误" + e.toString());
                    }
                    @Override
                    public void onNext(MoneyState bean) {
                        //返回成功 数据处理
                        EventBus.getDefault().post(bean, Constant.BUS_MY_TRANSFER);
                    }
                });
        mApiService.getCompositeSubscription(mTaskId).add(subscription);
    }

    /**
     * 转账记录
     */
    public void userTransferList(int storeId,int pageIndex,int pageSize) {
        Subscription subscription = mUserAPI
                .userTransferList(storeId,pageIndex,pageSize).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<List<TransferList>>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        //返回成功 数据处理
                        EventBus.getDefault().post(e.toString(), Constant.BUS_MY_TRANSFER_LIST_ERROR);
                        //log 打印
                        Log.e(mActivity.getClass().getSimpleName(),"structureList 错误" + e.toString());
                    }
                    @Override
                    public void onNext(List<TransferList> list) {

                        if(RefType== Constant.FIRST_LOAD){
                            //返回成功 首次加载数据处理
                            EventBus.getDefault().post(list, Constant.BUS_MY_TRANSFER_LIST);
                        }else{
                            //返回成功 上拉加载数据处理
                            EventBus.getDefault().post(list, Constant.BUS_MY_TRANSFER_LIST_FOOT);
                        }
                    }
                });
        mApiService.getCompositeSubscription(mTaskId).add(subscription);
    }

    /**
     * 获取库存
     */
    public void userStockQueryList(int storeId,int pageIndex,int pageSize) {
        Subscription subscription = mUserAPI
                .userStockQueryList(storeId,pageIndex,pageSize).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<StockQueryJsonPack>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        //返回成功 数据处理
                        EventBus.getDefault().post(e.toString(), Constant.BUS_MY_STOCK_QUERY_LIST_ERROR);
                        //log 打印
                        Log.e(mActivity.getClass().getSimpleName(),"structureList 错误" + e.toString());
                    }
                    @Override
                    public void onNext(StockQueryJsonPack pack) {

                        if(RefType== Constant.FIRST_LOAD){
                            //返回成功 首次加载数据处理
                            EventBus.getDefault().post(pack, Constant.BUS_MY_STOCK_QUERY_LIST);
                        }else{
                            //返回成功 上拉加载数据处理
                            EventBus.getDefault().post(pack, Constant.BUS_MY_STOCK_QUERY_LIST_FOOT);
                        }
                    }
                });
        mApiService.getCompositeSubscription(mTaskId).add(subscription);
    }


    /**
     * 卡号进货
     */
    public void userCardPurchase(int storeId, int CardOf170Num,int CMCC_CardNum, int unicomCardNum,
                                 int telecomCardNum, String linkTel,String shippingAddress, String shoppingMethod) {
        Subscription subscription = mUserAPI
                .userCardPurchase(storeId, CardOf170Num, CMCC_CardNum, unicomCardNum,telecomCardNum,
                        linkTel,shippingAddress,shoppingMethod).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<State>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        //加载出错,可用于 “页面” 提示信息
                        EventBus.getDefault().post("onCompleted", Constant.BUS_PURCHASE_CARD_ERROR);
                        //log 打印
                        Log.e(mActivity.getClass().getSimpleName(),"structureList 错误" + e.toString());
                    }
                    @Override
                    public void onNext(State bean) {
                        //返回成功 数据处理
                        EventBus.getDefault().post(bean, Constant.BUS_PURCHASE_CARD);
                    }
                });
        mApiService.getCompositeSubscription(mTaskId).add(subscription);
    }

    /**
     * 进货订单 记录
     */
    public void userPurchaseOrderList(int storeId,int pageIndex,int pageSize) {
        Subscription subscription = mUserAPI
                .userPurchaseOrderList(storeId,pageIndex,pageSize).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<List<PurchaseOrder>>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        //返回成功 数据处理
                        EventBus.getDefault().post(e.toString(), Constant.BUS_MY_PURCHASE_ORDER_LIST_ERROR);
                        //log 打印
                        Log.e(mActivity.getClass().getSimpleName(),"structureList 错误" + e.toString());
                    }
                    @Override
                    public void onNext(List<PurchaseOrder> list) {

                        if(RefType== Constant.FIRST_LOAD){
                            //返回成功 首次加载数据处理
                            EventBus.getDefault().post(list, Constant.BUS_MY_PURCHASE_ORDER_LIST);
                        }else{
                            //返回成功 上拉加载数据处理
                            EventBus.getDefault().post(list, Constant.BUS_MY_PURCHASE_ORDER_LIST_FOOT);
                        }
                    }
                });
        mApiService.getCompositeSubscription(mTaskId).add(subscription);
    }

    /**
     * 号卡销售 记录
     */
    public void userCardSalesList(int storeId,int pageIndex,int pageSize,String startTime,String endTime) {
        Subscription subscription = mUserAPI
                .userCardSalesList(storeId,pageIndex,pageSize,startTime,endTime).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<SalesRecordJsonPack>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        //返回成功 数据处理
                        EventBus.getDefault().post(e.toString(), Constant.BUS_MY_SALES_CARD_LIST_ERROR);
                        //log 打印
                        Log.e(mActivity.getClass().getSimpleName(),"structureList 错误" + e.toString());
                    }
                    @Override
                    public void onNext(SalesRecordJsonPack pack) {

                        if(RefType== Constant.FIRST_LOAD){
                            //返回成功 首次加载数据处理
                            EventBus.getDefault().post(pack, Constant.BUS_MY_SALES_CARD_LIST);
                        }else{
                            //返回成功 上拉加载数据处理
                            EventBus.getDefault().post(pack, Constant.BUS_MY_SALES_CARD_LIST_FOOT);
                        }
                    }
                });
        mApiService.getCompositeSubscription(mTaskId).add(subscription);
    }

    /**
     * 宽带销售 记录
     */
    public void userInstallSalesList(int storeId,int pageIndex,int pageSize,String startTime,String endTime) {
        Subscription subscription = mUserAPI
                .userInstallSalesList(storeId,pageIndex,pageSize,startTime,endTime).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<SalesRecordJsonPack>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        //返回成功 数据处理
                        EventBus.getDefault().post(e.toString(), Constant.BUS_MY_SALES_INSTALL_LIST_ERROR);
                        //log 打印
                        Log.e(mActivity.getClass().getSimpleName(),"structureList 错误" + e.toString());
                    }
                    @Override
                    public void onNext(SalesRecordJsonPack pack) {

                        if(RefType== Constant.FIRST_LOAD){
                            //返回成功 首次加载数据处理
                            EventBus.getDefault().post(pack, Constant.BUS_MY_SALES_INSTALL_LIST);
                        }else{
                            //返回成功 上拉加载数据处理
                            EventBus.getDefault().post(pack, Constant.BUS_MY_SALES_INSTALL_LIST_FOOT);
                        }
                    }
                });
        mApiService.getCompositeSubscription(mTaskId).add(subscription);
    }

    /**
     * 修改用户头像
     */
    public void userUpdateIcon(int StoreId,String url) {
        Subscription subscription = mUserAPI
                .userUpdateIcon(StoreId,url).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<State>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        //加载出错,可用于 “页面” 提示信息
                        EventBus.getDefault().post("onCompleted", Constant.BUS_MY_UPDATE_USER_ICON_ERROR);
                        //log 打印
                        Log.e(mActivity.getClass().getSimpleName(),"structureList 错误" + e.toString());
                    }
                    @Override
                    public void onNext(State bean) {
                        //返回成功 数据处理
                        EventBus.getDefault().post(bean, Constant.BUS_MY_UPDATE_USER_ICON);
                    }
                });
        mApiService.getCompositeSubscription(mTaskId).add(subscription);
    }

    /**
     * 新建支付密码
     */
    public void userNewTsPwd(int StoreId,String tsPwd) {
        Subscription subscription = mUserAPI
                .userNewTsPwd(StoreId,tsPwd).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<State>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        //加载出错,可用于 “页面” 提示信息
                        EventBus.getDefault().post("onCompleted", Constant.BUS_MY_NEW_PAY_PWD_ERROR);
                        //log 打印
                        Log.e(mActivity.getClass().getSimpleName(),"structureList 错误" + e.toString());
                    }
                    @Override
                    public void onNext(State bean) {
                        //返回成功 数据处理
                        EventBus.getDefault().post(bean, Constant.BUS_MY_NEW_PAY_PWD);
                    }
                });
        mApiService.getCompositeSubscription(mTaskId).add(subscription);
    }

    /**
     * 修改支付密码
     */
    public void userSetTsPwd(int StoreId,String oldTsPwd,String newTsPwd) {
        Subscription subscription = mUserAPI
                .userSetTsPwd(StoreId,oldTsPwd,newTsPwd).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<State>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        //加载出错,可用于 “页面” 提示信息
                        EventBus.getDefault().post("onCompleted", Constant.BUS_MY_UPDATE_PAY_PWD_ERROR);
                        //log 打印
                        Log.e(mActivity.getClass().getSimpleName(),"structureList 错误" + e.toString());
                    }
                    @Override
                    public void onNext(State bean) {
                        //返回成功 数据处理
                        EventBus.getDefault().post(bean, Constant.BUS_MY_UPDATE_PAY_PWD);
                    }
                });
        mApiService.getCompositeSubscription(mTaskId).add(subscription);
    }

    /**
     * 忘记支付密码 重置支付密码
     */
    public void userEditTsPwdOfForget(String sessionId,String vocde,String mobile,String tsPwd) {
        Subscription subscription = mUserAPI
                .userEditTsPwdOfForget(sessionId,vocde,mobile,tsPwd).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<State>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        //加载出错,可用于 “页面” 提示信息
                        EventBus.getDefault().post("onCompleted", Constant.BUS_MY_PAY_FORGET_RESET_ERROR);
                        //log 打印
                        Log.e(mActivity.getClass().getSimpleName(),"structureList 错误" + e.toString());
                    }
                    @Override
                    public void onNext(State bean) {
                        //返回成功 数据处理
                        EventBus.getDefault().post(bean, Constant.BUS_MY_PAY_FORGET_RESET);
                    }
                });
        mApiService.getCompositeSubscription(mTaskId).add(subscription);
    }

    /**
     * 验证支付密码
     */
    public void userCheckPayPwd(int storeId,String tsPwd) {
        Subscription subscription = mUserAPI
                .userCheckPayPwd(storeId,tsPwd).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<State>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        //加载出错,可用于 “页面” 提示信息
                        EventBus.getDefault().post("onCompleted", Constant.BUS_MY_CHECK_PAY_ERROR);
                        //log 打印
                        Log.e(mActivity.getClass().getSimpleName(),"structureList 错误" + e.toString());
                    }
                    @Override
                    public void onNext(State bean) {
                        //返回成功 数据处理
                        EventBus.getDefault().post(bean, Constant.BUS_MY_CHECK_PAY);
                    }
                });
        mApiService.getCompositeSubscription(mTaskId).add(subscription);
    }

    /**
     * 验证 号卡订单 支付密码
     */
    public void userCardCheckPayPwd(int storeId,String tsPwd) {
        Subscription subscription = mUserAPI
                .userCheckPayPwd(storeId,tsPwd).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<State>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        //加载出错,可用于 “页面” 提示信息
                        EventBus.getDefault().post("onCompleted", Constant.BUS_MY_CARD_CHECK_PAY_ERROR);
                        //log 打印
                        Log.e(mActivity.getClass().getSimpleName(),"structureList 错误" + e.toString());
                    }
                    @Override
                    public void onNext(State bean) {
                        //返回成功 数据处理
                        EventBus.getDefault().post(bean, Constant.BUS_MY_CARD_CHECK_PAY);
                    }
                });
        mApiService.getCompositeSubscription(mTaskId).add(subscription);
    }

    /**
     * 修改登录密码
     */
    public void userUpdateLoginPwd(int StoreId,String oldLoginPwd,String newLoginPwd) {
        Subscription subscription = mUserAPI
                .userUpdateLoginPwd(StoreId,oldLoginPwd,newLoginPwd).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<State>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        //加载出错,可用于 “页面” 提示信息
                        EventBus.getDefault().post("onCompleted", Constant.BUS_MY_UPDATE_LOGIN_PWD_ERROR);
                        //log 打印
                        Log.e(mActivity.getClass().getSimpleName(),"structureList 错误" + e.toString());
                    }
                    @Override
                    public void onNext(State bean) {
                        //返回成功 数据处理
                        EventBus.getDefault().post(bean, Constant.BUS_MY_UPDATE_LOGIN_PWD);
                    }
                });
        mApiService.getCompositeSubscription(mTaskId).add(subscription);
    }



    /**
     * 忘记登录密码 重置支付密码
     */
    public void userUsedLoginPwd(String sessionId,String vocde,String mobile,String pwd) {
        Subscription subscription = mUserAPI
                .userUsedLoginPwd(sessionId,vocde,mobile,pwd).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<State>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        //加载出错,可用于 “页面” 提示信息
                        EventBus.getDefault().post("onCompleted", Constant.BUS_MY_USED_LOGIN_PWD_ERROR);
                        //log 打印
                        Log.e(mActivity.getClass().getSimpleName(),"structureList 错误" + e.toString());
                    }
                    @Override
                    public void onNext(State bean) {
                        //返回成功 数据处理
                        EventBus.getDefault().post(bean, Constant.BUS_MY_USED_LOGIN_PWD);
                    }
                });
        mApiService.getCompositeSubscription(mTaskId).add(subscription);
    }

    /**
     * 修改店铺信息
     */
    public void userUpdateShop(int storeId,String storeName,String mobile,
                                 String area,String address, String linkTel,
                                 String countermanName,String countermanTel) {
        Subscription subscription = mUserAPI
                .userUpdateShop(storeId,storeName,mobile,area,address,linkTel,countermanName,countermanTel).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<State>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        //加载出错,可用于 “页面” 提示信息
                        EventBus.getDefault().post("onCompleted", Constant.BUS_MY_UPDATE_SHOP_ERROR);
                        //log 打印
                        Log.e(mActivity.getClass().getSimpleName(),"structureList 错误" + e.toString());
                    }
                    @Override
                    public void onNext(State bean) {
                        //返回成功 数据处理
                        EventBus.getDefault().post(bean, Constant.BUS_MY_UPDATE_SHOP);
                    }
                });
        mApiService.getCompositeSubscription(mTaskId).add(subscription);
    }


    /**
     * 转账记录
     */
    public void userTradeList(int storeId,int pageIndex,int pageSize) {
        Subscription subscription = mUserAPI
                .userTradeList(storeId,pageIndex,pageSize).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<List<TradeList>>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        //返回成功 数据处理
                        EventBus.getDefault().post(e.toString(), Constant.BUS_MY_TRADE_LIST_ERROR);
                        //log 打印
                        Log.e(mActivity.getClass().getSimpleName(),"structureList 错误" + e.toString());
                    }
                    @Override
                    public void onNext(List<TradeList> list) {

                        if(RefType== Constant.FIRST_LOAD){
                            //返回成功 首次加载数据处理
                            EventBus.getDefault().post(list, Constant.BUS_MY_TRADE_LIST);
                        }else{
                            //返回成功 上拉加载数据处理
                            EventBus.getDefault().post(list, Constant.BUS_MY_TRADE_LIST_FOOT);
                        }
                    }
                });
        mApiService.getCompositeSubscription(mTaskId).add(subscription);
    }


    /**
     * 奖惩记录
     */
    public void userPrizePunishList(int storeId,int pageIndex,int pageSize) {
        Subscription subscription = mUserAPI
                .userPrizePunishList(storeId,pageIndex,pageSize).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<List<PrizePunish>>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        //返回成功 数据处理
                        EventBus.getDefault().post(e.toString(), Constant.BUS_MY_PUNISH_LIST_ERROR);
                        //log 打印
                        Log.e(mActivity.getClass().getSimpleName(),"structureList 错误" + e.toString());
                    }
                    @Override
                    public void onNext(List<PrizePunish> list) {

                        if(RefType== Constant.FIRST_LOAD){
                            //返回成功 首次加载数据处理
                            EventBus.getDefault().post(list, Constant.BUS_MY_PUNISH_LIST);
                        }else{
                            //返回成功 上拉加载数据处理
                            EventBus.getDefault().post(list, Constant.BUS_MY_PUNISH_LIST_FOOT);
                        }
                    }
                });
        mApiService.getCompositeSubscription(mTaskId).add(subscription);
    }


    /**
     * 推送消息记录
     */
    public void userMsgNoticeList(int storeId,int pageIndex,int pageSize) {
        Subscription subscription = mUserAPI
                .userMsgNoticeList(storeId,pageIndex,pageSize).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<List<MsgNotice>>() {
                    @Override
                    public void onCompleted() {
                    }
                    @Override
                    public void onError(Throwable e) {
                        //返回成功 数据处理
                        EventBus.getDefault().post(e.toString(), Constant.BUS_MY_MSG_NOTICE_LIST_ERROR);
                        //log 打印
                        Log.e(mActivity.getClass().getSimpleName(),"structureList 错误" + e.toString());
                    }
                    @Override
                    public void onNext(List<MsgNotice> list) {

                        if(RefType== Constant.FIRST_LOAD){
                            //返回成功 首次加载数据处理
                            EventBus.getDefault().post(list, Constant.BUS_MY_MSG_NOTICE_LIST);
                        }else{
                            //返回成功 上拉加载数据处理
                            EventBus.getDefault().post(list, Constant.BUS_MY_MSG_NOTICE_LIST_FOOT);
                        }
                    }
                });
        mApiService.getCompositeSubscription(mTaskId).add(subscription);
    }
}
